<%@ taglib prefix="c" uri="jakarta.tags.core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <base href="<%=request.getContextPath()%>/">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>患者中心 - 医疗预约系统</title>
    <link rel="stylesheet" href="statics/css/hisStyle.css">
    <style>
        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
        }
        .header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 30px;
            padding-bottom: 15px;
            border-bottom: 1px solid #eee;
        }
        .header h1 {
            color: #2c3e50;
            margin: 0;
        }
        .logout-btn {
            background-color: #e74c3c;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 5px;
            cursor: pointer;
            text-decoration: none;
        }
        .logout-btn:hover {
            background-color: #c0392b;
        }
        .profile-container {
            display: flex;
            gap: 30px;
            margin-bottom: 40px;
        }
        .sidebar {
            width: 250px;
            background: white;
            border-radius: 10px;
            padding: 20px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }
        .user-info {
            text-align: center;
            margin-bottom: 20px;
        }
        .avatar {
            width: 80px;
            height: 80px;
            border-radius: 50%;
            object-fit: cover;
            max-width: 100%;
            max-height: 100%;
            margin-bottom: 15px;
            border: 3px solid #3498db;
            object-fit: cover;
        }
        .menu-list {
            list-style: none;
            padding: 0;
            margin: 0;
        }
        .menu-item {
            margin-bottom: 5px;
        }
        .menu-link {
            display: block;
            padding: 12px 15px;
            color: #555;
            text-decoration: none;
            border-radius: 5px;
            transition: all 0.3s;
        }
        .menu-link:hover {
            background-color: #f5f5f5;
            color: #3498db;
        }
        .menu-link.active {
            background-color: #3498db;
            color: white;
        }
        .content {
            flex: 1;
            background: white;
            border-radius: 10px;
            padding: 30px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }
        .welcome-section {
            text-align: center;
            padding: 40px 20px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border-radius: 10px;
            margin-bottom: 30px;
        }
        .welcome-section h2 {
            margin-bottom: 10px;
            font-size: 32px;
        }
        .welcome-section p {
            margin-bottom: 20px;
            font-size: 18px;
        }
        .action-cards {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 20px;
            margin-bottom: 30px;
        }
        .action-card {
            background: white;
            border-radius: 10px;
            padding: 30px;
            text-align: center;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            transition: transform 0.3s ease;
            border: 1px solid #e0e0e0;
        }
        .action-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
        }
        .action-icon {
            font-size: 48px;
            margin-bottom: 15px;
        }
        .action-card h3 {
            color: #2c3e50;
            margin-bottom: 10px;
        }
        .action-card p {
            color: #7f8c8d;
            margin-bottom: 20px;
        }
        .btn-primary {
            background-color: #3498db;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 5px;
            cursor: pointer;
            text-decoration: none;
            font-size: 16px;
            transition: background-color 0.3s;
        }
        .btn-primary:hover {
            background-color: #2980b9;
        }
        .recent-appointments {
            margin-top: 30px;
        }
        .section-title {
            color: #2c3e50;
            margin-bottom: 20px;
            font-size: 24px;
            border-left: 4px solid #3498db;
            padding-left: 15px;
        }
        .appointment-list {
            list-style: none;
            padding: 0;
            margin: 0;
        }
        .appointment-item {
            padding: 15px;
            border: 1px solid #eee;
            border-radius: 8px;
            margin-bottom: 10px;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        .appointment-info {
            flex: 1;
        }
        .appointment-hospital {
            font-weight: bold;
            color: #2c3e50;
            margin-bottom: 5px;
        }
        .appointment-date {
            color: #7f8c8d;
            font-size: 14px;
        }
        .status-badge {
            padding: 4px 12px;
            border-radius: 20px;
            font-size: 12px;
            font-weight: bold;
        }
        .status-pending {
            background-color: #fff3cd;
            color: #856404;
        }
        .status-paid {
            background-color: #d4edda;
            color: #155724;
        }
        .status-completed {
            background-color: #cce5ff;
            color: #004085;
        }
        .no-appointments {
            text-align: center;
            padding: 40px 20px;
            color: #95a5a6;
        }
        @media (max-width: 768px) {
            .profile-container {
                flex-direction: column;
            }
            .sidebar {
                width: 100%;
            }
            .action-cards {
                grid-template-columns: 1fr;
            }
        }
    </style>
    <script>
        $(function() {
            // 显示注册成功欢迎提示
            const urlParams = new URLSearchParams(window.location.search);
            if (urlParams.has('registered')) {
                $('#welcomeModal').modal('show');
                // 3秒后自动关闭
                setTimeout(function() {
                    $('#welcomeModal').modal('hide');
                }, 3000);
            }
        });
    </script>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>医疗预约系统 - 患者中心</h1>
            <a href="auth/logout" class="logout-btn">退出登录</a>
        </div>

        <div class="profile-container">
            <!-- 侧边菜单 -->
            <div class="sidebar">
                <div class="user-info">
                    <img src="statics/images/adminHead/${loginUser != null && loginUser.headpic != null ? loginUser.headpic : 'default.png'}" alt="用户头像" class="avatar">
                    <h3>${loginUser != null ? (loginUser.realName != null ? loginUser.realName : loginUser.username) : '用户'}</h3>
                    <p>普通用户</p>
                </div>
                <ul class="menu-list">
                    <li class="menu-item"><a href="frontend/patient-index" class="menu-link active">首页</a></li>
                    <li class="menu-item"><a href="frontend/profile" class="menu-link">个人信息</a></li>
                    <li class="menu-item"><a href="frontend/my-appointments" class="menu-link">预约记录</a></li>
                    <li class="menu-item"><a href="frontend/my-reports" class="menu-link">就诊记录</a></li>
                    <li class="menu-item"><a href="frontend/index" class="menu-link">浏览医院</a></li>
                </ul>
            </div>

            <!-- 主要内容 -->
            <div class="content">
                <div class="welcome-section">
                    <h2>欢迎回来，${loginUser != null ? (loginUser.realName != null ? loginUser.realName : loginUser.username) : '用户'}</h2>
                    <p>便捷的医疗服务，从这里开始</p>
                </div>

                <div class="action-cards">
                    <div class="action-card">
                        <div class="action-icon">🏥</div>
                        <h3>预约挂号</h3>
                        <p>选择医院和科室，预约您需要的医生</p>
                        <a href="frontend/index" class="btn-primary">立即预约</a>
                    </div>
                    <div class="action-card">
                        <div class="action-icon">📋</div>
                        <h3>我的预约</h3>
                        <p>查看和管理您的所有预约记录</p>
                        <a href="frontend/my-appointments" class="btn-primary">查看预约</a>
                    </div>
                    <div class="action-card">
                        <div class="action-icon">📝</div>
                        <h3>就诊记录</h3>
                        <p>查看您的历史就诊记录和医生建议</p>
                        <a href="frontend/my-reports" class="btn-primary">查看记录</a>
                    </div>
                </div>

                <div class="recent-appointments">
                    <h3 class="section-title">最近预约</h3>
                    
                    <c:choose>
                        <c:when test="${not empty recentAppointments}">
                            <ul class="appointment-list">
                                <c:forEach items="${recentAppointments}" var="appointment" varStatus="status">
                                    <li class="appointment-item">
                                        <div class="appointment-info">
                                            <div class="appointment-hospital">${appointment.visit.department.hospital.hospitalName} - ${appointment.visit.department.deptName}</div>
                                            <div class="appointment-date">就诊日期：${appointment.visit.visitDate} ${appointment.visit.timeSlot}</div>
                                        </div>
                                        <div class="status-badge status-${appointment.status == 0 ? 'pending' : appointment.status == 1 ? 'paid' : appointment.status == 2 ? 'completed' : 'cancelled'}">
                                            <c:choose>
                                                <c:when test="${appointment.status == 0}">待支付</c:when>
                                                <c:when test="${appointment.status == 1}">已支付</c:when>
                                                <c:when test="${appointment.status == 2}">已完成</c:when>
                                                <c:otherwise>已取消</c:otherwise>
                                            </c:choose>
                                        </div>
                                    </li>
                                </c:forEach>
                            </ul>
                        </c:when>
                        <c:otherwise>
                            <div class="no-appointments">
                                <p>暂无最近预约记录</p>
                                <a href="frontend/index">去首页预约</a>
                            </div>
                        </c:otherwise>
                    </c:choose>
                </div>
            </div>
        </div>
    </div>
    
    <!-- 注册成功欢迎模态框 -->
    <div class="modal fade" id="welcomeModal" tabindex="-1" role="dialog">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" style="color: #28a745;">🎉 欢迎使用！</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <p>注册成功！您现在可以享受我们提供的全部服务了。</p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" data-dismiss="modal">确定</button>
                </div>
            </div>
        </div>
    </div>
</body>
</html>